<?php
    session_start();
    include_once("checkAuthenticationAction.php");
    include_once("../service/articleService.php");
    include_once("../util/constant.php");
    include_once("../util/FTP.php");
    
    $title = $_POST["articleTitle"];
    $page = $_POST["page"];
    $content = $_POST["content"];
    $thumbnail = $_POST["thumbnail"];
    
    $result = createArticle($title,$page, $content, $thumbnail);
    $new_id = mysql_insert_id();
    if($result){
        if(IS_ON_SERVER) FTP::getInstance()->ftpRename(FTP::getInstance()->getServerPath()."tmp/article/".session_id(), 
                                                       FTP::getInstance()->getServerPath()."article/".$new_id);
        else rename("../image/tmp/article/".session_id(), "../image/article/".$new_id);
        echo "<script>window.location.href='../admin/article.php';</script>";    
    }else{
        echo "<script>window.location.href='../admin/article-detail.php?action=".NEW_ACTION."';</script>";
    }
    
?>
